package net.xumf.support.enums;

import lombok.Getter;
import net.xumf.support.exception.NotFoundEnumInfoException;

import java.util.Arrays;

/**
 * 任务运行状态
 */
@Getter
public enum QuartzTriggerState {

    NONE(0, "不存在"),
    NORMAL(1, "正常"),
    PAUSED(2, "暂停"),
    COMPLETE(3, "完成"),
    ERROR(4, "错误"),
    BLOCKED(5, "阻塞"),;

    private int code;
    private String msg;

    QuartzTriggerState(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public String getMsg() {
        return msg;
    }

    public static QuartzTriggerState getByCode(int code) {
        return Arrays.stream(values()).filter(o -> o.code == code).findAny()
                .orElseThrow(() -> new NotFoundEnumInfoException(CodeEnum.ENUM_NOT_FOUND_ERROR));
    }
}
